

class login {
	constructor(oText, oPwd, obtn) {
		this.oText = oText;
		this.oPwd = oPwd;
		this.obtn = obtn;
	}
	logins() {

		obtn.onclick = function() {
			// 手机验证
			let xhr = new XMLHttpRequest();
			xhr.open("post", "../php/login.php", true);
			//post的传参方式必须在open方法后设置请求头:将数据以form表单的方式的传递
			xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			let uname = document.getElementById("input-text1").value;
			let pwd = document.getElementById("input-text2").value;
			let msg = `name=${uname}&pwd=${pwd}`;
			xhr.send(msg);
			xhr.onreadystatechange = function() {
				if (xhr.status == 200 && xhr.readyState == 4) {
					fun(xhr.responseText);
				}
			}

			function fun(resText) {
				let p = document.querySelector("p");
				 p.innerHTML = resText;
				 console.log(resText)
				if (resText==0) {
					 console.log("111")
				 	// window.location.href="./register.js";
				 }
				if (resText==1) {
					 console.log("222")
				 	location.href="../index.html";
				 } 
			}
		}

	}
}

let oText = document.querySelector(".input-text1");
let oPwd = document.querySelector(".input-text2");
let obtn = document.querySelector(".user-default-btn");
let l = new login(oText, oPwd, obtn);

l.logins();
